package com.zzyl.mapper;

import com.zzyl.dto.UserDto;
import com.zzyl.entity.SysUser;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface SysUserMapper {
    @Insert("INSERT INTO sys_user (username, open_id, password, user_type, avatar, nick_name, email, real_name, mobile, sex, data_state, dept_no, post_no, create_time, update_time, remark, create_by, update_by, is_leader, is_delete) " +
            "VALUES (#{username}, #{openId}, #{password}, #{userType}, #{avatar}, #{nickName}, #{email}, #{realName}, #{mobile}, #{sex}, #{dataState}, #{deptNo}, #{postNo}, #{createTime}, #{updateTime}, #{remark}, #{createBy}, #{updateBy}, #{isLeader}, #{isDelete})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insert(UserDto userDto);

    @Delete("DELETE FROM sys_user WHERE id = #{id}")
    int deleteById(Long id);

    @Update("UPDATE sys_user SET username = #{username}, open_id = #{openId}, password = #{password}, user_type = #{userType}, avatar = #{avatar}, nick_name = #{nickName}, email = #{email}, " +
            "real_name = #{realName}, mobile = #{mobile}, sex = #{sex}, data_state = #{dataState}, dept_no = #{deptNo}, post_no = #{postNo}, create_time = #{createTime}, update_time = #{updateTime}, " +
            "remark = #{remark}, create_by = #{createBy}, update_by = #{updateBy}, is_leader = #{isLeader}, is_delete = #{isDelete} WHERE id = #{id}")
    int update(SysUser sysUser);

    @Select("SELECT * FROM sys_user WHERE id = #{id}")
    SysUser getById(Long id);

    @Select("SELECT * FROM sys_user")
    List<SysUser> getAll();
}